package com.huan.web;

import com.alibaba.fastjson.JSON;
import com.huan.pojo.Count;
import com.huan.pojo.PageBean;
import com.huan.service.CountService;
import com.huan.service.impl.CountServiceImpl;
import com.huan.web.base.BaseServlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet("/depart/*")
public class CountServlet extends BaseServlet {
    CountService service = new CountServiceImpl();

    /**
     * 院系根据性别统计人数
     * @param request
     * @param response
     * @throws Exception
     */
    public void demo(HttpServletRequest request, HttpServletResponse response) throws Exception{

        List<Count> pageBean = service.demo();


        String s = JSON.toJSONString(pageBean);

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write(s);
    }

    /**
     * 院系按性别统计人数
     * @param request
     * @param response
     * @throws Exception
     */
    public void countOriginPlace(HttpServletRequest request, HttpServletResponse response) throws Exception{

        List<Count> pageBean = service.countOriginPlace();


        String s = JSON.toJSONString(pageBean);

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write(s);
    }

    public void countFile(HttpServletRequest request, HttpServletResponse response) throws Exception{

        List<Count> pageBean = service.countFile();


        String s = JSON.toJSONString(pageBean);

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write(s);
    }

    public void selectCountPlace(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String _currentPage = request.getParameter("currentPage");
        String _pageSize = request.getParameter("pageSize");

        int currentPage = Integer.parseInt(_currentPage);
        int pageSize = Integer.parseInt(_pageSize);

        PageBean<Count> pageBean = service.selectCountPlace(currentPage, pageSize);

        String s = JSON.toJSONString(pageBean);

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write(s);
    }

    public void toSexCountAvg(HttpServletRequest request, HttpServletResponse response) throws Exception{

        List<Count> pageBean = service.toSexCountAvg();

        String s = JSON.toJSONString(pageBean);

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write(s);
    }

    public void toCourseAvg(HttpServletRequest request, HttpServletResponse response) throws Exception{

        List<Count> countPageBean = service.toCourseAvg();

        String s = JSON.toJSONString(countPageBean);

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write(s);
    }

    public void studentCourse(HttpServletRequest request, HttpServletResponse response) throws Exception{

        List<Count> counts = service.studentCourse();

        String s = JSON.toJSONString(counts);

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write(s);
    }
}
